using System;
using DevExpress.Xpo;
using SmartPeople.Framework.SecuritySpace;

namespace SmartPeople.Framework.Security.Providers.XPO
{
    [Persistent("SecurityPermission")]
    public class XPSecurityPermission : XPCustomObject, ISecurityPermission
    {
        #region Old Constructor
        //public XPSecurityPermission(Guid securityRoleID, Guid securedDocumentID, Guid actionID, Guid stateID,
        //                            AccessType accessType)
        //{
        //    this.securityRoleID = securityRoleID;
        //    this.securedDocumentID = securedDocumentID;
        //    this.actionID = actionID;
        //    this.stateID = stateID;
        //    this.accessType = accessType;
        //} 
        #endregion

        public XPSecurityPermission()
        {
        }

        public XPSecurityPermission(Session session)
            : base(session)
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here.
        }

        #region Fields

        [Key(AutoGenerate = true)]
        [Persistent("GID")]
        private Guid gID;

        [Persistent("SecurityRoleID")]
        private Guid securityRoleID;

        [Persistent("SecuredDocumentID")]
        private Guid securedDocumentID;

        [Persistent("ActionID")]
        private Guid actionID;

        [Persistent("StateID")]
        private Guid stateID;

        [Persistent("AccessType")]
        private AccessType accessType;

        #endregion

        #region Properties

        [NonPersistent]
        public Guid GID
        {
            get { return gID; }
            set
            {
                if (gID != value)
                {
                    Guid OldValue = gID;
                    gID = value;
                    OnChanged("GID", OldValue, value);
                }
            }
        }

        [NonPersistent]
        public Guid SecurityRoleID
        {
            get { return securityRoleID; }
            set
            {
                if (securityRoleID != value)
                {
                    Guid OldValue = securityRoleID;
                    securityRoleID = value;
                    OnChanged("SecurityRoleID", OldValue, value);
                }
            }
        }

        [NonPersistent]
        public Guid SecuredDocumentID
        {
            get { return securedDocumentID; }
            set
            {
                if (securedDocumentID != value)
                {
                    Guid OldValue = securedDocumentID;
                    securedDocumentID = value;
                    OnChanged("SecuredDocumentID", OldValue, value);
                }
            }
        }

        [NonPersistent]
        public Guid ActionID
        {
            get { return actionID; }
            set
            {
                if (actionID != value)
                {
                    Guid OldValue = actionID;
                    actionID = value;
                    OnChanged("ActionID", OldValue, value);
                }
            }
        }

        [NonPersistent]
        public Guid StateID
        {
            get { return stateID; }
            set
            {
                if (stateID != value)
                {
                    Guid OldValue = stateID;
                    stateID = value;
                    OnChanged("StateID", OldValue, value);
                }
            }
        }

        [NonPersistent]
        public AccessType AccessType
        {
            get { return accessType; }
            set
            {
                if (accessType != value)
                {
                    AccessType OldValue = accessType;
                    accessType = value;
                    OnChanged("AccessType", OldValue, value);
                }
            }
        }

        #endregion
    }
}